package com.ruoyi.system.controller;

import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.system.domain.RandomVo;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SjStandard;
import com.ruoyi.system.service.ISjStandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 双随机标准Controller
 * 
 * @author ruoyi
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/system/standard")
public class SjStandardController extends BaseController
{
    @Autowired
    private ISjStandardService sjStandardService;

    /**
     * 查询双随机标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:standard:list')")
    @GetMapping("/list")
    public TableDataInfo list(SjStandard sjStandard)
    {
        startPage();
        List<SjStandard> list = sjStandardService.selectSjStandardList(sjStandard);
        return getDataTable(list);
    }

    /**
     * 导出双随机标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:standard:export')")
    @Log(title = "双随机标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SjStandard sjStandard)
    {
        List<SjStandard> list = sjStandardService.selectSjStandardList(sjStandard);
        ExcelUtil<SjStandard> util = new ExcelUtil<SjStandard>(SjStandard.class);
        util.exportExcel(response, list, "双随机标准数据");
    }

    /**
     * 上传标准文件
     */
    @PostMapping("/upload")
    public String upload(MultipartFile file)
    {
        String filePath="";
        try {
            filePath = FileUploadUtils.upload(file);
        }catch (Exception e){

        }
        return filePath;
    }

    /**
     * 导入双随机标准列表
     */
    @Log(title = "双随机标准", businessType = BusinessType.EXPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("filePath")String filePath, @RequestParam("category")String category)
    {
        return sjStandardService.importData(filePath,category);
    }

    /**
     * 随机标准
     */
    @Log(title = "双随机标准", businessType = BusinessType.EXPORT)
    @PostMapping("/randomStandard")
    public AjaxResult randomStandard(RandomVo randomVo)
    {
        List<SjStandard> list = sjStandardService.randomData(randomVo);
        return AjaxResult.success("抽取成功",list);
    }

    /**
     * 随机标准
     */
    @Log(title = "双随机标准", businessType = BusinessType.EXPORT)
    @PostMapping("/randomStandardDown")
    public void randomStandardDown(HttpServletResponse response,RandomVo randomVo)
    {
        List<SjStandard> list = sjStandardService.randomData(randomVo);
        ExcelUtil<SjStandard> util = new ExcelUtil<SjStandard>(SjStandard.class);
        util.exportExcel(response, list, "双随机标准数据");
    }

    /**
     * 获取双随机标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:standard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sjStandardService.selectSjStandardById(id));
    }

    /**
     * 新增双随机标准
     */
    @PreAuthorize("@ss.hasPermi('system:standard:add')")
    @Log(title = "双随机标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SjStandard sjStandard)
    {
        return toAjax(sjStandardService.insertSjStandard(sjStandard));
    }

    /**
     * 修改双随机标准
     */
    @PreAuthorize("@ss.hasPermi('system:standard:edit')")
    @Log(title = "双随机标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SjStandard sjStandard)
    {
        return toAjax(sjStandardService.updateSjStandard(sjStandard));
    }

    /**
     * 删除双随机标准
     */
    @PreAuthorize("@ss.hasPermi('system:standard:remove')")
    @Log(title = "双随机标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sjStandardService.deleteSjStandardByIds(ids));
    }
}
